home *** CD-ROM | disk | FTP | other *** search
- package sub_arctic.lib;
-
- import sub_arctic.output.loaded_image;
- import sub_arctic.output.drawable;
- import java.awt.Color;
- import java.util.Vector;
-
- /**
- * This the class that knows how to the display-side work of displaying
- * a vertical scrollbar. It handles outputting a scrollbar from a
- * set of state variables.
- *
- * @author Scott Hudson
- */
- public class v_slider_display extends base_interactor {
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This variable is a boolean which says if you want a box around the
- * slider or not.
- */
- protected boolean _boxed=true;
-
- /**
- * Return whether or not the user wants a box around the slider or
- * not.
- * @return boolean true if the user wants the slider boxed
- */
- public boolean boxed(){ return _boxed;};
-
- /**
- * Modify whether or not to box the slider.
- *
- * @param boolean b the new boxed state variable
- */
- public void set_boxed(boolean b) { _boxed=b;
- damage_self();
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /* this is here so subclasses can draw the thumb at places other than
- * against the left edge of the interactor. This is a shift in the *X*
- * direction. */
-
- /**
- * This variable is how much to offset (in x and in pixels) the slider's
- * thumb by when drawing it.
- */
- protected int _thumb_shift=0;
-
- /**
- * Return how much to shift the thumb by (in x, and in pixels).
- * @return int how much to shift the thumb by (in x, and in pixels).
- */
- public int thumb_shift() { return _thumb_shift;}
-
- /**
- * Change the amount to shift the thumb by (in the x direction)
- * @param int v the amount to shift the thumb by in pixels
- */
- public void set_thumb_shift(int v) {
- _thumb_shift=v;
- damage_self();
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Image for the up button */
- protected loaded_image _up_img;
-
- /**
- * Image for the up button
- *
- * @return the up image.
- */
- public loaded_image up_img() {return _up_img;}
-
- /**
- * Set the image for the up button
- *
- * @param loaded_image img the image to use for the up button
- */
- public void set_up_img(loaded_image img) {
- _up_img = img;
- damage_self();
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Image for the down button */
- protected loaded_image _dn_img;
-
- /**
- * Image for the down button
- *
- * @return the down image.
- */
- public loaded_image dn_img() {return _dn_img;}
-
- /**
- * Set the image for the down button
- *
- * @param loaded_image img the image to use for the down button
- */
- public void set_dn_img(loaded_image img) {
- _dn_img = img;
- damage_self();
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Image for the "thumb" */
- protected loaded_image _thumb_img;
-
- /**
- * Image for the thumb
- *
- * @return the right image.
- */
- public loaded_image thumb_img() {return _thumb_img;}
-
- /**
- * Set the image for the thumb of the slider
- *
- * @param loaded_image img the image to use for the thumb
- */
- public void set_thumb_img(loaded_image img) {
- _thumb_img = img;
- damage_self();
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Image for the background -- use null for a default solid color */
- protected loaded_image _back_img;
-
- /**
- * Image for the background (pattern). You'll get null for a default
- * solid color.
- *
- * @return the background image
- */
- public loaded_image back_img() {return _back_img;}
-
- /**
- * Set the image for the background -- use null for a default solid color
- *
- * @param loaded_image img the image for the background of the slider
- */
- public void set_back_img(loaded_image img) {
- _back_img = img;
- damage_self();
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Minimum value of the slider */
- protected int _min_val;
-
- /** Minimum value of the slider
- * @return int the minimum value of the slider */
- public int min_val() {return _min_val;}
-
- /**
- * Set the minimum value of the slider
- *
- * @param int val the new minimum value of the slider.
- */
- public void set_min_val(int val) {
- _min_val = val;
- damage_self();
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Maximum value of the slider */
- protected int _max_val;
-
- /** Maximum value of the slider
- * @return the maximum value of the slider*/
- public int max_val() {return _max_val;}
-
- /**
- * Set the maximum value of the slider
- *
- * @param int val the new maximum value of the slider.
- */
- public void set_max_val(int val) {
- _max_val = val;
- damage_self();
- }
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Small increment value */
- protected int _small_inc;
-
- /**
- * Return the small increment value (this is the amount the slider's
- * value changes when you push the end buttons).
- *
- * @return int the small increment value of the slider
- */
- public int small_inc() {return _small_inc;}
-
- /**
- * Set the small increment value (amount the value changes when you click on
- * the end buttons.
- *
- * @param int val the new small increment
- */
- public void set_small_inc(int val) {_small_inc = val;}
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Large increment value */
- protected int _large_inc;
-
- /**
- * Return the large increment value (this is the amount the slider's
- * value changes when you click in the thumb area but not on the thumb).
- *
- * @return int the large increment value of the slider
- */
- public int large_inc() {return _large_inc;}
-
- /**
- * Set the large increment value (amount the value changes when you
- * click on the thumb area but not on the thumb).
- *
- * @param int val the new small increment
- */
- public void set_large_inc(int val) {_large_inc = val;}
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Return the value of the part_a component of this object. In our case
- * this is stored in _value.
- *
- * @return int the value of part_a.
- */
- public int part_a()
- {
- /* Make sure its up to date and in range then return it */
- eval_part_a();
- conform();
- return _value;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Set part_a value directly bypassing the constraint system (but doing
- * damage). This should normally only be done by the constraint system
- * or some other part of the system which takes care of marking things
- * out-of-date, etc. itself. In this case part_a is stored in _value.
- *
- * @param int v the new value of part_a.
- */
- protected void set_raw_part_a(int v)
- {
- /* don't do anything unless this is a change */
- if (v != _value)
- {
- /* make change and do damage */
- _value = v;
- conform();
- damage_self();
- }
- }
-
- //had:
- //* @exception general PROPAGATED.
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Set the part_a component of this object. In our case this is stored in
- * _value.
- * @parm int v the new value.
- */
- public void set_part_a(int v)
- {
- /* if this has a constraint throw an exception */
- if ((active_constraints() & PART_A) != 0)
- throw new sub_arctic_error(
- "Attempt to assign value to constrained part_a " +
- "(AKA h_slider_display.value)");
-
- /* don't do anything unless this is a change */
- if (v != _value)
- {
- set_raw_part_a(v);
- mark_part_a_ood();
- }
- }
-
- //had:
- //* @exception cannot_assign if the value is constrained.
- //* @exception general PROPAGATED.
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Current value of the slider */
- protected int _value;
-
- /**
- * Current value of the slider
- * @return int the value of the slider.
- */
- public int value() {return part_a();}
-
- /**
- * Set the current value of the slider
- * @param int val the new value of the slider
- */
- public void set_value(int val)
- {
- set_part_a(val);
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Full constructor for the v_slider_display. If you do not supply
- * an image for any of the image slots (i.e. you pass null) a default
- * look will be applied for you.
- *
- * @param int xv x position of the slider.
- * @param int yv y position of the slider.
- * @param int hv height of the slider (in pixels).
- * @param int minv minimum value of the slider.
- * @param int maxv maximum value of the slider.
- * @param int init_val initial value of the slider.
- * @param int sincv small increment value.
- * @param int lincv large increment value.
- * @param loaded_image up_im image for the up button.
- * @param loaded_image dn_im image for the down button.
- * @param loaded_image th_im image for the thumb.
- * @param loaded_image back_pat image for the background of the slider.
- */
- public v_slider_display(
- int xv, int yv, int hv,
- int minv, int maxv,
- int init_val,
- int sincv, int lincv,
- loaded_image up_im, loaded_image dn_im, loaded_image th_im,
- loaded_image back_pat)
- {
- /* let the superclass init (with dummy temporary width) */
- super(xv,yv, 21,hv);
-
- /* initialize locals */
- _min_val = minv; _max_val = maxv;
- _value = init_val;
- _small_inc = sincv; _large_inc = lincv;
-
- _up_img = up_im; _dn_img = dn_im; _thumb_img = th_im;
- _back_img = back_pat;
-
- /* use defaults for any nulls */
- if (_up_img == null) _up_img = std.v_slider_up();
- if (_dn_img == null) _dn_img = std.v_slider_down();
- if (_thumb_img == null) _thumb_img = std.v_slider_thumb();
- if (_back_img == null) _back_img = std.v_slider_back();
-
- /* now reset the width to the real width */
- int max_w = 0;
- if (max_w < _up_img.width()) max_w = _up_img.width();
- if (max_w < _dn_img.width()) max_w = _dn_img.width();
- if (max_w < _thumb_img.width()) max_w = _thumb_img.width();
- set_intrinsic_w(max_w);
-
- /* make sure values are all in range and in order */
- conform();
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Construct a new v_slider_display with the artkit look.
- *
- * @param int xv x position of the slider.
- * @param int yv y position of the slider.
- * @param int hv height of the slider (in pixels).
- * @param int minv minimum value of the slider.
- * @param int maxv maximum value of the slider.
- * @param int init_val initial value of the slider.
- * @param int sincv small increment value.
- * @param int lincv large increment value.
- */
- public v_slider_display(
- int xv, int yv, int hv,
- int minv, int maxv,
- int init_val,
- int sincv, int lincv)
- {
- this(xv,yv,hv,minv,maxv,init_val,sincv,lincv, null, null, null, null);
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Make sure min <= max and min <= value <= max
- */
- protected void conform()
- {
- int t;
-
- /* make sure min, max are still ok */
- if (_min_val > _max_val)
- {
- t = _min_val; _min_val = _max_val; _max_val = t;
- }
-
- /* force value in range */
- if (_value < _min_val) {_value = _min_val;}
- if (_value > _max_val) {_value = _max_val;}
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Indicate that we intrinsically constrain width. Thus, the width
- * is not modifiable by either the programmer or user.
- * @return int bitset indicating intrinsically constrained parts.
- */
- public int intrinsic_constraints()
- {
- return W;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Compute the offset to the thumb in pixels (returns -1 for no thumb)
- *
- * @return int the amount the thumb should be shifted down to account for
- * the value of the slider.
- */
- protected int thumb_offset()
- {
- int off, slide_range, value_range;
-
- /* compute ranges for thumb */
- slide_range = h() - _up_img.height()-_dn_img.height()-_thumb_img.height();
- value_range = max_val() - min_val();
-
- /* return negative if there is no room for the thumb */
- /*
- * Added Keith's fix for thumbs that are exactly fitting
- */
- if (slide_range < 0 || value_range < 0) return -1;
- /**
- * Added Keith's fix for avoiding a divide by zero.
- */
- if (slide_range == 0 || value_range == 0) return 0;
-
- /* otherwise compute drawing offset for thumb */
- off = (value() - min_val()) * slide_range / value_range;
- if (off < 0) off = 0;
- if (off > slide_range) off = slide_range;
-
- return off;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Draw the current image on the drawable provided.
- *
- * @param drawable d a drawable for the image or screen you want this object
- * drawn on.
- */
- protected void draw_self_local(drawable d)
- {
- int off;
-
- /* fill the rectangle behind the slider */
- if (_back_img != null)
- {
- d.tileImage(_back_img, 0,0, w()-1,h()-1);
- }
-
- /* compute offset for thumb */
- off = thumb_offset();
-
- /* draw the thumb if we have room for one */
- if (off >= 0)
- {
- d.drawImage(_thumb_img, thumb_shift(),_up_img.height()+off);
- }
-
- /* draw the buttons */
- d.drawImage(_up_img,0,0);
- d.drawImage(_dn_img,0,h()-_dn_img.height());
-
- /* if boxed is true, draw a box around the whole thing */
- if (boxed()) {
- d.setColor(Color.black);
- d.drawRect(0,0, w()-1,h()-1);
- }
- }
-
- //had:
- //* @exception general PROPAGATED.
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- }
- /*=========================== COPYRIGHT NOTICE ===========================
-
- This file is part of the subArctic user interface toolkit.
-
- Copyright (c) 1996 Scott Hudson and Ian Smith
- All rights reserved.
-
- The subArctic system is freely available for most uses under the terms
- and conditions described in
- http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html
- and appearing in full in the lib/interactor.java source file.
-
- The current release and additional information about this software can be
- found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
-
- ========================================================================*/
-